package config

import (
	"log"

	"github.com/spf13/viper"
)

type Config struct {
	App struct {
		Name               string `mapstructure:"name"`
		Port               string `mapstructure:"port"`
		SingleSessionLogin bool   `mapstructure:"singleSessionLogin"`
	} `mapstructure:"app" json:"app" yaml:"app"`

	Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`

	Jwt JWT `mapstructure:"jwt" json:"jwt" yaml:"jwt"`

	Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
}

var AppConfig *Config

func InitConfig() {
	viper.SetConfigName("config")
	viper.SetConfigType("yaml")
	viper.AddConfigPath("./config")

	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Error reading config file, %s", err)
	}

	if err := viper.Unmarshal(&AppConfig); err != nil {
		log.Fatalf("Error unmarshalling config, %s", err)
	}
}
